/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package swengine;

import java.io.IOException;
import java.net.URL;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;

/**
 *
 * @author Patrik
 */
public class SSound
{
	Clip clip;

	public SSound()
	{
		try
		{
			clip = AudioSystem.getClip();
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
	
	public SSound(final URL url)
	{
		System.out.println(url);
		try
		{
			clip = AudioSystem.getClip();
			AudioInputStream inputStream = AudioSystem.getAudioInputStream(url);
			clip.open(inputStream);
		}
		catch (Exception ex)
		{
				ex.printStackTrace();
		}
	}
	
	public boolean load(URL url)
	{
		try
		{
			AudioInputStream inputStream = AudioSystem.getAudioInputStream(url);
			clip.open(inputStream);
			return true;
		}
		catch (Exception ex)
		{
			return false;
		}
	}


	public boolean play()
	{
		try
		{
			clip.start();
			return true;
		}
		catch (Exception ex)
		{
			return false;
		}
	}

	public boolean stop()
	{
		try
		{
			clip.stop();
			return true;
		}
		catch (Exception ex)
		{
			return false;
		}
	}
}
